package com.wwwarehouse.contract.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wwwarehouse.common.activity.base.BaseApplication;
import com.wwwarehouse.contract.bean.ChooseModuleBean;
import com.wwwarehouse.contract.bean.CustomerAndResListBean;

import java.util.ArrayList;
import java.util.List;

import contract.wwwarehouse.com.contract.R;

/**
 * Created by feng.gao on 2017/9/22.
 */

public class SelectResourceFactorShipResourcesAdapter extends BaseAdapter {
	private List<CustomerAndResListBean.Customers> list = new ArrayList<>();
	private Context context;

	public SelectResourceFactorShipResourcesAdapter(List<CustomerAndResListBean.Customers> list, Context context) {
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final ViewHolder viewHolder;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.supply_of_resources_item, null);
			viewHolder = new ViewHolder();
			viewHolder.supplyIv = (ImageView) convertView.findViewById(R.id.supply_resource_iv);
			viewHolder.supplyTv = (TextView) convertView.findViewById(R.id.supply_resource_tv);
			viewHolder.mContentLayout = (LinearLayout) convertView.findViewById(R.id.content_layout);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		if (list != null && list.size()>0) {
			viewHolder.supplyTv.setText(list.get(position).getName());
			if (list.get(position).isSelected()) {
				viewHolder.mContentLayout.setBackground(context.getResources().getDrawable(R.drawable.blue_circle_eight_five_bg));
				viewHolder.supplyTv.setTextColor(context.getResources().getColor(R.color.common_color_c3_ffffff));
				if (list.get(position).getSelectUrl() != null )
				BaseApplication.getApplicationInstance().displayImg(list.get(position).getSelectUrl(), viewHolder.supplyIv);
			} else {
				viewHolder.mContentLayout.setBackground(context.getResources().getDrawable(R.drawable.circle_gray_rescource_bg));
				viewHolder.supplyTv.setTextColor(context.getResources().getColor(R.color.common_color_c7_96999e));
				if (list.get(position).getDefaultUrl() != null ) {
					BaseApplication.getApplicationInstance().displayImg(list.get(position).getDefaultUrl(), viewHolder.supplyIv);
				}
			}
//			viewHolder.client_tv.setText(list.get(position).getTitle());

//				BaseApplication.getApplicationInstance().displayImg(list.get(position).getGrayUrl() , viewHolder.supplyIv);


		}
		return convertView;
	}

	class ViewHolder {
		TextView supplyTv;
		ImageView supplyIv;
		LinearLayout mContentLayout;

	}


}